package com.newbee.http;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.multipart.FilePart;
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.commons.httpclient.methods.multipart.StringPart;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;

import com.newbee.app.AppConfig;
import com.newbee.fragement.multchat.MultChatFragement;
import com.newbee.listbean.FriendsInfoBean;
import com.newbee.sound.Sound;

public class ServerHttpUtil
{

	public static final int SUCCESS = 1;
	public static final int FALSE = 0;

	/******************************/
	private static final String CONFERENCE = "conference";
	private static final String OWNER = "owner";
	private static final String VOICE_FILE = "voiceFile";
	private static final String TAG = "tag";

	public static int userUpLoad(File voiceFile, String conference, String owner)
	{

		String acton = "voiceupload";
		UTF8PostMethod filePost = new UTF8PostMethod(AppConfig.HTTP + acton);//
		filePost.getParams().setContentCharset("UTF-8");
		filePost.getParams().setParameter(
				HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
		try
		{

			StringPart sp = new StringPart(OWNER, owner);
			sp.setCharSet("UTF-8");
			// 设置post参数
			Part[] paras = { new StringPart(CONFERENCE, conference), sp,

			new FilePart(VOICE_FILE, voiceFile) };
			// 设置传输实体
			filePost.setRequestEntity(new MultipartRequestEntity(paras,
					new HttpMethodParams()));

			HttpClient client = new HttpClient();

			client.getHttpConnectionManager().getParams()
					.setConnectionTimeout(5000);// 请求超时设定

			int status = client.executeMethod(filePost);// 执行post方法
			if (status == HttpStatus.SC_OK)
			{

				return SUCCESS;
				// 上传成功
			}
			else
			{
				return FALSE;
				// 上传失败
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
			return FALSE;

		}
		finally
		{
			filePost.releaseConnection();
		}

	}

	public static int userUpLoad(File voiceFile, String conference,
			String owner, int langtype)
	{

		String action = "voiceupload";
		String enaction = "ENvoiceupload";

		UTF8PostMethod filePost = null;
		if (langtype == MultChatFragement.CN)
		{
			filePost = new UTF8PostMethod(AppConfig.HTTP + action);//
		}
		else
		{
			filePost = new UTF8PostMethod(AppConfig.HTTP + enaction);//
		}
		filePost.getParams().setContentCharset("UTF-8");
		filePost.getParams().setParameter(
				HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
		try
		{

			StringPart sp = new StringPart(OWNER, owner);
			sp.setCharSet("UTF-8");
			// 设置post参数
			Part[] paras = { new StringPart(CONFERENCE, conference), sp,

			new FilePart(VOICE_FILE, voiceFile) };
			// 设置传输实体
			filePost.setRequestEntity(new MultipartRequestEntity(paras,
					new HttpMethodParams()));

			HttpClient client = new HttpClient();

			client.getHttpConnectionManager().getParams()
					.setConnectionTimeout(5000);// 请求超时设定

			int status = client.executeMethod(filePost);// 执行post方法
			if (status == HttpStatus.SC_OK)
			{

				return SUCCESS;
				// 上传成功
			}
			else
			{
				return FALSE;
				// 上传失败
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
			return FALSE;

		}
		finally
		{
			filePost.releaseConnection();
		}

	}

	/*****************************/

	private static final String CONF_NAME = "name";

	private static final String CONF_USER = "qunzuUser";

	private static final String CONF_ISOWNER = "isOwner";

	public static final String IS_OWNER_TRUE = "1";
	public static final String IS_OWNER_FALSE = "2";

	public static int conferenceReg(String conferenceName, String user,
			String isOwner)
	{

		String acton = "qunzureg";
		UTF8PostMethod filePost = new UTF8PostMethod(AppConfig.HTTP + acton);//
		filePost.getParams().setContentCharset("UTF-8");
		filePost.getParams().setParameter(
				HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
		try
		{
			// 设置post参数
			Part[] paras = { new StringPart(CONF_NAME, conferenceName),
					new StringPart(CONF_USER, user),
					new StringPart(CONF_ISOWNER, isOwner) };
			// 设置传输实体
			filePost.setRequestEntity(new MultipartRequestEntity(paras,
					new HttpMethodParams()));

			HttpClient client = new HttpClient();

			client.getHttpConnectionManager().getParams()
					.setConnectionTimeout(5000);// 请求超时设定
			int status = client.executeMethod(filePost);// 执行post方法
			if (status == HttpStatus.SC_OK)
			{

				return SUCCESS;
			}
			else
			{
				return FALSE;
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
			return FALSE;

		}
		finally
		{
			filePost.releaseConnection();
		}

	}

	private static String USER = "user";

	public static JSONArray getQunZu(String user)
	{

		List<NameValuePair> postParameters = new ArrayList<NameValuePair>();

		postParameters.add(new BasicNameValuePair(USER, user));

		String acton = "getqunzu";
		JSONArray result = null;
		try
		{

			// http 请求
			HttpPost request = new HttpPost(AppConfig.HTTP + acton);
			// 加入请求参数
			UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(
					postParameters, HTTP.UTF_8);
			// 设置请求实体

			request.setEntity(formEntity);

			// 执行请求
			HttpResponse httpResponse = new DefaultHttpClient()
					.execute(request);
			// 获取返回字符串
			String retSrc = EntityUtils.toString(httpResponse.getEntity());

			// 构造json
			result = new JSONArray(retSrc);
			Log.d("WCH", "return json----->>>" + retSrc);

		}
		catch (Exception e)
		{
			Log.d("WCH", e.toString());
		}
		finally
		{
			return result;
		}

	}

	/*****************************************************/

	public static String FILE = "file";

	public static String simgleVoiceFile(String file)
	{

		String acton = "singletrans";
		UTF8PostMethod filePost = new UTF8PostMethod(AppConfig.HTTP + acton);//
		filePost.getParams().setContentCharset("UTF-8");
		filePost.getParams().setParameter(
				HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
		try
		{
			// 设置post参数
			File voiceFile = new File(Sound.DIR + file);
			Part[] paras = { new FilePart(FILE, voiceFile) };
			// 设置传输实体
			filePost.setRequestEntity(new MultipartRequestEntity(paras,
					new HttpMethodParams()));

			HttpClient client = new HttpClient();

			client.getHttpConnectionManager().getParams()
					.setConnectionTimeout(55000);// 请求超时设定

			int status = client.executeMethod(filePost);// 执行post方法

			ByteArrayOutputStream bos = new ByteArrayOutputStream();
			BufferedInputStream bis = new BufferedInputStream(
					filePost.getResponseBodyAsStream());

			int length;
			byte[] buffer = new byte[1024];

			while ((length = bis.read(buffer)) > 0)
			{
				bos.write(buffer, 0, length);
			}
			bos.flush();
			bis.close();
			String resultString = new String(bos.toByteArray());
			bos.close();

			return resultString;

		}
		catch (Exception ex)
		{
			ex.printStackTrace();
			return null;

		}
		finally
		{
			filePost.releaseConnection();
		}
	}

	public static String simgleVoiceFile(String file, String type)
	{

		String acton = "singletrans";
		UTF8PostMethod filePost = new UTF8PostMethod(AppConfig.HTTP + acton);//
		filePost.getParams().setContentCharset("UTF-8");
		filePost.getParams().setParameter(
				HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
		try
		{
			// 设置post参数
			File voiceFile = new File(Sound.DIR + file);
			Part[] paras = { new FilePart(FILE, voiceFile),
					new StringPart("type", type) };
			// 设置传输实体
			filePost.setRequestEntity(new MultipartRequestEntity(paras,
					new HttpMethodParams()));

			HttpClient client = new HttpClient();

			client.getHttpConnectionManager().getParams()
					.setConnectionTimeout(55000);// 请求超时设定

			int status = client.executeMethod(filePost);// 执行post方法

			ByteArrayOutputStream bos = new ByteArrayOutputStream();
			BufferedInputStream bis = new BufferedInputStream(
					filePost.getResponseBodyAsStream());

			int length;
			byte[] buffer = new byte[1024];

			while ((length = bis.read(buffer)) > 0)
			{
				bos.write(buffer, 0, length);
			}
			bos.flush();
			bis.close();
			String resultString = new String(bos.toByteArray());
			bos.close();

			return resultString;

		}
		catch (Exception ex)
		{
			ex.printStackTrace();
			return null;

		}
		finally
		{
			filePost.releaseConnection();
		}
	}

	/*****************************************/

	public static String EMAIL = "email";
	public static String NICK_NAME = "nickname";

	public static String HEAD = "head";

	public static String PASSWORD = "password";

	public static void userReg(String email, String nickName, String head,
			String password, String username)
	{

		// NewBeeHttpClient.SubmitPost(email, nickName, head, password);
		String acton = "userreg";
		UTF8PostMethod filePost = new UTF8PostMethod(AppConfig.HTTP + acton);//
		filePost.getParams().setContentCharset("UTF-8");
		filePost.getParams().setParameter(
				HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
		try
		{
			File imgFile = new File(Sound.DIR + head);
			// 设置post参数
			StringPart sPart = new StringPart("username", username);

			sPart.setCharSet("UTF-8");
			Part[] paras = { new StringPart(EMAIL, email),
					new StringPart(NICK_NAME, nickName),
					new StringPart(HEAD, head),
					new StringPart(PASSWORD, password), sPart,
					new FilePart(FILE, imgFile) };
			// 设置传输实体
			filePost.setRequestEntity(new MultipartRequestEntity(paras,
					new HttpMethodParams()));

			HttpClient client = new HttpClient();

			client.getHttpConnectionManager().getParams()
					.setConnectionTimeout(55000);// 请求超时设定

			int status = client.executeMethod(filePost);// 执行post方法

			return;

		}
		catch (Exception ex)
		{
			ex.printStackTrace();
			return;

		}
		finally
		{
			filePost.releaseConnection();
		}
	}

	/*****************************************/

	public static String GET_NICKNAME_EMAIL = "email";

	public static String getNiceName(String email)
	{

		String acton = "getnickname";
		UTF8PostMethod filePost = new UTF8PostMethod(AppConfig.HTTP + acton);//
		filePost.getParams().setContentCharset("UTF-8");
		filePost.getParams().setParameter(
				HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
		try
		{
			// 设置post参数
			Part[] paras = { new StringPart(GET_NICKNAME_EMAIL, email) };
			// 设置传输实体
			filePost.setRequestEntity(new MultipartRequestEntity(paras,
					new HttpMethodParams()));

			HttpClient client = new HttpClient();

			client.getHttpConnectionManager().getParams()
					.setConnectionTimeout(55000);// 请求超时设定

			int status = client.executeMethod(filePost);// 执行post方法

			return filePost.getResponseBodyAsString();
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
			return null;

		}
		finally
		{
			filePost.releaseConnection();
		}
	}

	/****************************************************/

	private static final String QUNZU_NAME = "qunzuName";
	private static final String OwnerName = "qunzuOwnerName";
	private static final String Users = "qunzuUser";

	public static void postQunZuInfo(String qunzuName, String ownerName,
			String user)
	{

		String acton = "createqnzu";
		UTF8PostMethod filePost = new UTF8PostMethod(AppConfig.HTTP + acton);//
		filePost.getParams().setContentCharset("UTF-8");
		filePost.getParams().setParameter(
				HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
		try
		{
			StringPart Qstringpart = new StringPart(QUNZU_NAME, qunzuName);
			Qstringpart.setCharSet("UTF-8");
			// 设置post参数
			Part[] paras = { Qstringpart, new StringPart(OwnerName, ownerName),
					new StringPart(Users, user) };
			// 设置传输实体
			filePost.setRequestEntity(new MultipartRequestEntity(paras,
					new HttpMethodParams()));

			HttpClient client = new HttpClient();

			client.getHttpConnectionManager().getParams()
					.setConnectionTimeout(55000);// 请求超时设定

			int status = client.executeMethod(filePost);// 执行post方法

			return;
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
			return;

		}
		finally
		{
			filePost.releaseConnection();
		}
	}

	/**********************************************************/

	public static boolean downVoiceFileName(String voiceFile)
	{

		String dir = "/User_Upload/";
		UTF8PostMethod filePost = new UTF8PostMethod(AppConfig.HTTP + dir
				+ voiceFile);//
		filePost.getParams().setContentCharset("UTF-8");
		filePost.getParams().setParameter(
				HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
		try
		{
			// 设置post参数
			Part[] paras = {};
			// 设置传输实体
			filePost.setRequestEntity(new MultipartRequestEntity(paras,
					new HttpMethodParams()));

			HttpClient client = new HttpClient();

			client.getHttpConnectionManager().getParams()
					.setConnectionTimeout(55000);// 请求超时设定

			int status = client.executeMethod(filePost);// 执行post方法

			InputStream is = filePost.getResponseBodyAsStream();

			BufferedInputStream bis = new BufferedInputStream(is);

			FileOutputStream fos = new FileOutputStream(Sound.DIR + voiceFile);

			byte[] buffer = new byte[2048];
			int length = 0;
			while ((length = bis.read(buffer)) > 0)
			{
				fos.write(buffer, 0, length);
			}
			bis.close();
			fos.flush();
			fos.close();
			return true;

		}
		catch (Exception ex)
		{
			ex.printStackTrace();
			return false;

		}
		finally
		{
			filePost.releaseConnection();
		}
	}

	/********************************************************/

	public static String ConfName = "confName";

	public static String multChatTrans(String confName)
	{

		String acton = "getmultchatresult";
		UTF8PostMethod filePost = new UTF8PostMethod(AppConfig.HTTP + acton);//
		filePost.getParams().setContentCharset("UTF-8");
		filePost.getParams().setParameter(
				HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
		try
		{
			// 设置post参数
			Part[] paras = { new StringPart(ConfName, confName) };
			// 设置传输实体
			filePost.setRequestEntity(new MultipartRequestEntity(paras,
					new HttpMethodParams()));

			HttpClient client = new HttpClient();

			client.getHttpConnectionManager().getParams()
					.setConnectionTimeout(55000);// 请求超时设定

			int status = client.executeMethod(filePost);// 执行post方法

			return filePost.getResponseBodyAsString();

		}
		catch (Exception ex)
		{
			ex.printStackTrace();
			return null;

		}
		finally
		{
			filePost.releaseConnection();
		}
	}

	/**********************************************/
	public static String RegEMIL = "email";

	public static String getVFcode(String email)
	{

		String acton = "regsendmail";
		UTF8PostMethod filePost = new UTF8PostMethod(AppConfig.HTTP + acton);//
		filePost.getParams().setContentCharset("UTF-8");
		filePost.getParams().setParameter(
				HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
		try
		{
			// 设置post参数
			Part[] paras = { new StringPart(RegEMIL, email) };
			// 设置传输实体
			filePost.setRequestEntity(new MultipartRequestEntity(paras,
					new HttpMethodParams()));

			HttpClient client = new HttpClient();

			client.getHttpConnectionManager().getParams()
					.setConnectionTimeout(55000);// 请求超时设定

			int status = client.executeMethod(filePost);// 执行post方法

			return filePost.getResponseBodyAsString();

		}
		catch (Exception ex)
		{
			ex.printStackTrace();
			return null;

		}
		finally
		{
			filePost.releaseConnection();
		}
	}

	/*******************************************************/
	public static String SrcStr = "srcstr";

	public static String getSpellChack(String srcString)
	{

		String acton = "regsendmail";
		UTF8PostMethod filePost = new UTF8PostMethod(AppConfig.HTTP + acton);//
		filePost.getParams().setContentCharset("UTF-8");
		filePost.getParams().setParameter(
				HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
		try
		{
			// 设置post参数
			Part[] paras = { new StringPart(SrcStr, srcString) };
			// 设置传输实体
			filePost.setRequestEntity(new MultipartRequestEntity(paras,
					new HttpMethodParams()));

			HttpClient client = new HttpClient();

			client.getHttpConnectionManager().getParams()
					.setConnectionTimeout(55000);// 请求超时设定

			int status = client.executeMethod(filePost);// 执行post方法

			return filePost.getResponseBodyAsString();

		}
		catch (Exception ex)
		{
			ex.printStackTrace();
			return null;

		}
		finally
		{
			filePost.releaseConnection();
		}
	}

	/*******************************************************/
	public static String FORGET_EMAIL = "email";

	public static boolean forgetPassowrd(String email)
	{

		String acton = "forgetpassword";
		UTF8PostMethod filePost = new UTF8PostMethod(AppConfig.HTTP + acton);//
		filePost.getParams().setContentCharset("UTF-8");
		filePost.getParams().setParameter(
				HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");

		try
		{
			// 设置post参数
			Part[] paras = { new StringPart(FORGET_EMAIL, email) };
			// 设置传输实体
			filePost.setRequestEntity(new MultipartRequestEntity(paras,
					new HttpMethodParams()));

			HttpClient client = new HttpClient();

			client.getHttpConnectionManager().getParams()
					.setConnectionTimeout(55000);// 请求超时设定

			int status = client.executeMethod(filePost);// 执行post方法

			return true;

		}
		catch (Exception ex)
		{
			ex.printStackTrace();
			return false;

		}
		finally
		{
			filePost.releaseConnection();
		}
	}

	/**************************************/
	/**
	 * 
	 * @param voiceFile
	 * @return
	 */
	public static final String HEAD_dir = "/User_Head/";

	public static Bitmap downHeadImg(String voiceFile)
	{

		UTF8PostMethod filePost = new UTF8PostMethod(AppConfig.HTTP + HEAD_dir
				+ voiceFile);//
		filePost.getParams().setContentCharset("UTF-8");
		filePost.getParams().setParameter(
				HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
		HttpMethodParams methodParams = new HttpMethodParams();
		methodParams.setContentCharset("UTF-8");
		try
		{
			// 设置post参数
			Part[] paras = {};
			// 设置传输实体
			filePost.setRequestEntity(new MultipartRequestEntity(paras,
					methodParams));

			HttpClient client = new HttpClient();

			client.getHttpConnectionManager().getParams()
					.setConnectionTimeout(55000);// 请求超时设定

			int status = client.executeMethod(filePost);// 执行post方法

			InputStream is = filePost.getResponseBodyAsStream();

			Bitmap headBitmap = BitmapFactory.decodeStream(is);

			return headBitmap;

		}
		catch (Exception ex)
		{
			ex.printStackTrace();
			return null;

		}
		finally
		{
			filePost.releaseConnection();
		}
	}

	/********************************************************/
	public static String content = "content";

	public static String upload(String str)
	{

		String acton = "qquplaod";
		UTF8PostMethod filePost = new UTF8PostMethod(AppConfig.HTTP + acton);//
		filePost.getParams().setContentCharset("UTF-8");
		filePost.getParams().setParameter(
				HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");

		HttpMethodParams httpMethodParams = new HttpMethodParams();
		httpMethodParams.setContentCharset("UTF-8");
		try
		{
			// 设置post参数
			// Part[] paras = { new StringPart(content, str) };
			// 设置传输实体
			org.apache.commons.httpclient.NameValuePair CONTENT = new org.apache.commons.httpclient.NameValuePair(
					content, str);
			filePost.setRequestBody(new org.apache.commons.httpclient.NameValuePair[] { CONTENT });
			// filePost.setRequestEntity(new MultipartRequestEntity(paras,
			// httpMethodParams));

			HttpClient client = new HttpClient();

			client.getHttpConnectionManager().getParams()
					.setConnectionTimeout(55000);// 请求超时设定

			int status = client.executeMethod(filePost);// 执行post方法

			return filePost.getResponseBodyAsString();

		}
		catch (Exception ex)
		{
			ex.printStackTrace();
			return null;

		}
		finally
		{
			filePost.releaseConnection();
		}
	}

	/***********************************************************************/
	public static String useremails = "useremails";

	public static String getUserName(List<FriendsInfoBean> list)
	{

		String acton = "getcnname";
		UTF8PostMethod filePost = new UTF8PostMethod(AppConfig.HTTP + acton);//
		filePost.getParams().setContentCharset("UTF-8");
		filePost.getParams().setParameter(
				HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");

		StringBuffer sb = new StringBuffer();
		int i = 0;
		for (i = 0; i < list.size() - 1; i++)
		{

			sb.append(list.get(i).getEmail().split("\\$")[0]);
			sb.append(";");
		}
		sb.append(list.get(i).getEmail().split("\\$")[0]);

		HttpMethodParams httpMethodParams = new HttpMethodParams();
		httpMethodParams.setContentCharset("UTF-8");
		try
		{
			org.apache.commons.httpclient.NameValuePair CONTENT = new org.apache.commons.httpclient.NameValuePair(
					useremails, sb.toString());
			filePost.setRequestBody(new org.apache.commons.httpclient.NameValuePair[] { CONTENT });

			HttpClient client = new HttpClient();

			client.getHttpConnectionManager().getParams()
					.setConnectionTimeout(55000);// 请求超时设定

			int status = client.executeMethod(filePost);// 执行post方法

			ByteArrayOutputStream bos = new ByteArrayOutputStream();
			BufferedInputStream bis = new BufferedInputStream(
					filePost.getResponseBodyAsStream());

			int length;
			byte[] buffer = new byte[1024];

			while ((length = bis.read(buffer)) > 0)
			{
				bos.write(buffer, 0, length);
			}
			bos.flush();
			bis.close();
			String resultString = new String(bos.toByteArray());
			bos.close();

			return resultString;

		}
		catch (Exception ex)
		{
			ex.printStackTrace();
			return null;

		}
		finally
		{
			filePost.releaseConnection();
		}
	}

	public static String getUserName(String paras)
	{

		String acton = "getcnname";
		UTF8PostMethod filePost = new UTF8PostMethod(AppConfig.HTTP + acton);//
		filePost.getParams().setContentCharset("UTF-8");
		filePost.getParams().setParameter(
				HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");

		HttpMethodParams httpMethodParams = new HttpMethodParams();
		httpMethodParams.setContentCharset("UTF-8");
		try
		{
			org.apache.commons.httpclient.NameValuePair CONTENT = new org.apache.commons.httpclient.NameValuePair(
					useremails, paras);
			filePost.setRequestBody(new org.apache.commons.httpclient.NameValuePair[] { CONTENT });

			HttpClient client = new HttpClient();

			client.getHttpConnectionManager().getParams()
					.setConnectionTimeout(55000);// 请求超时设定

			int status = client.executeMethod(filePost);// 执行post方法

			ByteArrayOutputStream bos = new ByteArrayOutputStream();
			BufferedInputStream bis = new BufferedInputStream(
					filePost.getResponseBodyAsStream());

			int length;
			byte[] buffer = new byte[1024];

			while ((length = bis.read(buffer)) > 0)
			{
				bos.write(buffer, 0, length);
			}
			bos.flush();
			bis.close();
			String resultString = new String(bos.toByteArray());
			bos.close();

			return resultString;

		}
		catch (Exception ex)
		{
			ex.printStackTrace();
			return null;

		}
		finally
		{
			filePost.releaseConnection();
		}
	}

	/*******************************************/
	public static String INPUT = "input";

	public static String checkSpeel(String input)
	{

		String acton = "checkspell";
		UTF8PostMethod filePost = new UTF8PostMethod(AppConfig.HTTP + acton);//
		filePost.getParams().setContentCharset("UTF-8");
		filePost.getParams().setParameter(
				HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
		try
		{
			// 设置post参数
			// File voiceFile = new File(Sound.DIR + file);

			StringPart sp = new StringPart(INPUT, input);
			sp.setCharSet("UTF-8");

			Part[] paras = { sp };
			// 设置传输实体
			filePost.setRequestEntity(new MultipartRequestEntity(paras,
					new HttpMethodParams()));

			HttpClient client = new HttpClient();

			client.getHttpConnectionManager().getParams()
					.setConnectionTimeout(55000);// 请求超时设定

			int status = client.executeMethod(filePost);// 执行post方法

			ByteArrayOutputStream bos = new ByteArrayOutputStream();
			BufferedInputStream bis = new BufferedInputStream(
					filePost.getResponseBodyAsStream());

			int length;
			byte[] buffer = new byte[1024];

			while ((length = bis.read(buffer)) > 0)
			{
				bos.write(buffer, 0, length);
			}
			bos.flush();
			bis.close();
			String resultString = new String(bos.toByteArray());
			bos.close();

			return resultString;

		}
		catch (Exception ex)
		{
			ex.printStackTrace();
			return null;

		}
		finally
		{
			filePost.releaseConnection();
		}
	}
}
